package com.zxl.admin.config;


import cn.dev33.satoken.stp.StpUtil;
import com.zxl.admin.interceptor.ApiTokenInterceptor;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * web的基本配置
 */
@Configuration
public class WebMvbConfig implements WebMvcConfigurer {

    @Resource
    private ApiTokenInterceptor apiTokenInterceptor;


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册Sa-Token的路由拦截器
        registry.addInterceptor(apiTokenInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/doc.html") //不需要拦截的地
                .excludePathPatterns("/swagger-resources/**")
                .excludePathPatterns("/webjars/**")
                .excludePathPatterns("/v2/**")
                .excludePathPatterns("/favicon.ico")
                .excludePathPatterns("/swagger-ui.html/**","/doc.html/**")
                .excludePathPatterns("/admin/user_login/login","/admin/common/upload","/admin/order/refundNotice");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/favicon.ico")
                .addResourceLocations("classpath:/static/");
    }

}
